﻿using ManageSystem.IRepository;
using ManageSystem.Model;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

// 级联插入project对象的repository

namespace ManageSystem.Repository
{
    public class ProjectRepository : BaseRepository<Project>, IProjectRepository
    {

        /// <summary>
        /// 根据username查询项目(多对多查询)
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public async Task<List<Project>> QueryProjectsByUserName(string username)
        {
            return await Db.Queryable<Project>().Where(it => it.creator == username).ToListAsync();
        }


        /// <summary>
        /// 判断是否存在名字重复的项目
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns></returns>
        public async Task<bool> isProjectNameRepated(string projectName)
        {
            return await Db.Queryable<Project>().Where(it => it.projectName == projectName).AnyAsync();
        }

    }
}
